
#include "ControllerBullet.h"

using namespace cgGame;


CControllerBullet::CControllerBullet()
	:CController()
{

	m_pPerception = CPerceptionFactory::CreatePerception(Character_Type_Bullet);
}



CControllerBullet::~CControllerBullet()
{
	SafeDelete(m_pPerception);
}



void CControllerBullet::CalcAction(float timeDelta)
{
	if (true == m_pPerception->IsCollisionWithTarget())
	{
		//m_pPerception->GetMyself()->SetIsAlive(false);
		m_pPerception->GetMyself()->ReduceLifeValue();
	}
	else
	{
		if (false == m_pPerception->GetMyself()->GetIsAlive())
		{
			return ;
		}

		cgVector2D currPos = m_pPerception->GetMyself()->GetObjPos();
		MoveWithDir(currPos);
		m_pPerception->PerceiveSurroundings();

		m_nextAction.SetPosition(currPos);
	}

}



void CControllerBullet::MoveWithDir(cgMath::cgVector2D& pos)
{
	Character_Dir tempDir = m_pPerception->GetMyself()->GetDirection();

	switch(tempDir)
	{
	case Character_Dir_Up:
		pos.y -= m_pPerception->GetMyself()->GetMoveSpeed();
		break;
	case Character_Dir_Down:
		pos.y += m_pPerception->GetMyself()->GetMoveSpeed();
		break;
	case Character_Dir_Left:
		pos.x -= m_pPerception->GetMyself()->GetMoveSpeed();
		break;
	case Character_Dir_Right:
		pos.x += m_pPerception->GetMyself()->GetMoveSpeed();
		break;
	default:
		break;
	}
}